﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo
{
	public class WeakReference<TObject>
	{
		protected WeakReference Reference { get; private set; }

		public static TObject ToTarget(WeakReference reference)
		{
			return (TObject)((reference == null) ? default(TObject) : reference.Target);
		}

		public WeakReference(TObject target)
		{
			this.Reference = new WeakReference(target);
		}
		public override string ToString()
		{
			return this.Reference.ToString();
		}
		public override int GetHashCode()
		{
			return this.Reference.GetHashCode();
		}
		public override bool Equals(object obj)
		{
			return this.Reference.Equals(obj);
		}

		public bool IsAlive { get { return this.Reference.IsAlive; } }
		public TObject Target { get { return (TObject)this.Reference.Target; } }
	}
}
